#include <bits/stdc++.h>
using namespace tsd;

struct car{
	int d,v,a;	
};

int n,m,L,V;
car c[100005];
int p[100005];
int memo[3005][3005],erf[3005][3005];
int carfl[3005];

void caseA(){
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(c[i].v>V) cnt++;
	}
	cout<<cnt<<" "<<m-1<<endl;
	return;
}

void smallcase(){
	for(int i=1;i<=n;i++){
		cin>>c[i].d>>c[i].v>>c[i].a;
	}
	int cnt=0;
	vector<int> s[m+1];
	memset(carfl,0,sizeof(carfl));
	memset(erf,0,sizeof(carfl))
	for(int i=1;i<=m;i++){
		cin>>p[i];
		for(int j=1;j<=n;j++){
			int dis=p[i]-c[j].d;
			if(dis<0){memo[i][j]=0;continue;}
			else if(dis==0){
				if(c[j].v>V){
					memo[i][j]=1;
					carfl[j]+=memo[i][j];
					s[i].push_back(j);
				}
				else memo[i][j]=0;
				continue;
			}
			else{
				double dxoverdt=sqrt(c[j].v*c[j].v+2*c[j].a*dis);
				if(dxoverdt>V){
					memo[i][j]=1;
					s[i].push_back(j);
				}
				else memo[i][j]=0;
				carfl[j]+=memo[i][j];
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(carfl[j]>0) cnt++;
	}
	int maxn=0;
	while(){
		maxn++;

	}
}

void largecase(){
	car c[n+1];
	int p[m+1];
	int C;
	for(int i=1;i<=n;i++){
		cin>>c[i].d>>c[i].v>>c[i].a;
		if(c[i].a==0)C=0;
		else if(c[i].a>0)C=1;
		else if(c[i].a<0) C=-1;
	}
	for(int i=1;i<=m;i++){
		cin>>p[i];
	}

	if(C==0) caseA();
	else if(C==1) caseB();
	else if(C==-1) caseC();
	return;
}

int main(){
	int T;
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	cin>>T;
	while(T--){
		cin>>n>>m>>L>>V;
		if(n<=3000 && m<=3000){
			smallcase();
		}
		else{
			largecase();
		}
	}
	return 0;
}
